package test.yzx.pproject.act2;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

import java.util.ArrayList;

import test.yzx.pproject.MemoryFragment;
import test.yzx.pproject.R;


public class MemoryActivity extends AppCompatActivity {

    private static ArrayList<Bitmap> list = new ArrayList<>();


    private TextView tv;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_memory);


        /* 当有savedInstanceState时候, 不用在添加fragment了, 系统会自动复原;  但是fragment里边的值不会保存, 需要在fragment内部自己保存 */
        if(savedInstanceState==null) {
            MemoryFragment f = new MemoryFragment();
            getFragmentManager().beginTransaction().replace(R.id.container, f, MemoryFragment.class.getName()).commit();
        }

    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
    }




    @Override
    public void onBackPressed() {
        increaseMemory();
    }

    /* increase memory */
    private void increaseMemory(){
        new Thread(){
            public void run() {
                for (int i = 0; i < 100; i++) {
                    list.add(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher));
                }
            }
        }.start();
    }

}
